package com.jeffse.light.stream.core.data.state;

import com.jeffse.light.stream.core.data.backend.StateBackends;
import com.jeffse.light.stream.core.data.context.LightStreamEnv;
import com.jeffse.light.stream.core.data.descriptor.stateDescriptor.StateDescriptor;
import lombok.Data;

import java.io.Serializable;

/**
 * 数据状态操作类
 */
@Data
public abstract class State<V> implements Serializable {
    protected StateBackends backends;
    protected StateDescriptor stateDescriptor;

    State(){
        backends = LightStreamEnv.getENV().getBackends();
    }

    /**
     * 清空状态数据
     */
    public void clear(){
        backends.clear(stateDescriptor);
    }

    /**
     * 保存或更新状态数据
     * @param v
     */
    public void update(V v){
        backends.update(stateDescriptor, v);
    }

}
